<template>
  <!-- 只能有一个div根标签 -->
  <el-dialog
    :title="proptitle == 1 ? '新增目录' : '删除目录'"
    width="400px"
    center
    :visible.sync="dialogFormVisible"
  >
    <el-form :model="subject" :rules="rules">
      <el-form-item label="所属学科" center prop="region">
        <el-select
          v-model="subject.region"
          style="width: 270px"
          placeholder="请选择"
        >
          <el-option
            v-for="item in subjectlist"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目录名称" center prop="name">
        <el-input
          style="width: 270px"
          v-model="subject.name"
          autocomplete="off"
          placeholder="请输入目录名称"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="addsubject">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  // 自定义组件名字(PascalCase)
  name: '',
  components: {},
  props: {
    subjectlist: {
      type: Array
    }
  },
  data () {
    return {
      proptitle: 1, // 目录标题 1 新增目录  0修改目录
      subject: {
        name: '', // 目录名称
        region: ''// 所属学科
      },
      dialogFormVisible: false, // 弹出层
      rules: {
        name: [
          { required: true, message: '请输入目录名称', trigger: 'blur' },
          { min: 6, max: 12, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请选择学科', trigger: 'change' }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  created () { },
  mounted () { },
  methods: {
    addsubject () {
      // 关闭弹出层
      this.dialogFormVisible = false
      // 传给头部添加
      this.$emit('addsubject', this.subject)
      // 传给修改
      this.$emit('revtivesubject', this.subject)
    }
  }
}
</script>

<style scoped>
</style>
